package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;

import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishMapper;
import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {
//    @Autowired
//    DishFlavorService dishFlavorService;

//    新增菜品，同时保存对应的口味数据
//    @Transactional  //操作了Dish 和DishFlavor 两张数据表 用注解来控制事务
//    public void saveWithFlavor(DishDto dishDto) {
        //保存菜品的基本信息到菜品表dish
//        this.save(dishDto);

//        Long dishId = dishDto.getId();//菜品id
        //菜品口味
//        List<DishFlavor> flavors = dishDto.getFlavors();
//        flavors = flavors.stream().map((item) -> {
//            item.setDishId(dishId);
//            return item;
//        }).collect(Collectors.toList());

        //保存菜品口味数据到菜品口味表dish_flavor
//        dishFlavorService.saveBatch(flavors);



//    }
}


